<template>
  <div id="addJobView">
    <a-select
      style="width: 80%; margin-bottom: 12px"
      placeholder="请选择您要为哪些学生提供以下岗位信息..."
      multiple
      :scrollbar="scrollbar"
      v-model="sids"
    >
      <a-option
        v-for="studentItem of studentList"
        :key="studentItem.id"
        :value="studentItem.id"
        :tag-props="{ color: 'blue' }"
      >
        {{ studentItem.name }}
      </a-option>
    </a-select>
    <a-form ref="formRef" :model="teacherPost" style="width: 80%">
      <a-form-item field="teacherPost.unitName" label="企业名称">
        <a-input
          v-model="teacherPost.unitName"
          placeholder="请输入企业名称..."
        />
      </a-form-item>
      <a-form-item field="teacherPost.address" label="工作地点">
        <a-input
          v-model="teacherPost.address"
          placeholder="请输入工作地点..."
        />
      </a-form-item>
      <a-form-item field="teacherPost.jobInfo" label="岗位详细信息">
        <a-textarea
          placeholder="请输入岗位详细信息..."
          v-model="teacherPost.jobInfo"
          :max-length="10"
          allow-clear
          show-word-limit
        />
      </a-form-item>
      <a-form-item field="teacherPost.phone" label="联系电话">
        <a-input v-model="teacherPost.phone" placeholder="请输入联系电话..." />
      </a-form-item>
      <a-form-item>
        <a-button @click="handleSubmit" type="primary">发布岗位信息</a-button>
      </a-form-item>
    </a-form>
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from "vue";
import {
  TeacherControllerService,
  TeacherPostControllerService,
} from "../../../generated";
import message from "@arco-design/web-vue/es/message";

let studentList = ref([
  {
    value: "",
    label: "",
  },
]);

const sids = ref([]);
const loginUserId = sessionStorage.getItem("LoginUserId");
const teacherPost = ref({
  jobInfo: "",
  unitName: "",
  address: "",
  phone: "",
  tid: loginUserId,
});
const scrollbar = ref(true);

onMounted(() => {
  loadData();
});

const loadData = async () => {
  const res = await TeacherControllerService.getStudentUsingGet();
  if (res.success === true) {
    studentList.value = res.data;
  } else {
    message.error("加载失败");
  }
};

const handleSubmit = async () => {
  console.log(sids);
  console.log(teacherPost.value);
  const res = await TeacherPostControllerService.insertJobProvidedUsingPut(
    teacherPost.value,
    sids.value
  );
  if (res.success === true) {
    message.success("岗位上传成功");
  } else {
    message.error("网络错误");
  }
};
</script>

<style scoped>
#addJobView {
}
</style>
